package cn.iocoder.lw.module.core.dal.mysql.project;

import cn.iocoder.lw.framework.common.pojo.PageResult;
import cn.iocoder.lw.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.lw.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.lw.module.core.controller.admin.project.vo.CoreProjectPageReqVO;
import cn.iocoder.lw.module.core.dal.dataobject.project.CoreProjectDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.Collection;
import java.util.List;

/**
 * 核心-项目 Mapper
 *
 * @author Lw源码
 */
@Mapper
public interface CoreProjectMapper extends BaseMapperX<CoreProjectDO> {

    default PageResult<CoreProjectDO> selectPage(CoreProjectPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<CoreProjectDO>()
                .likeIfPresent(CoreProjectDO::getName, reqVO.getName())
                .eqIfPresent(CoreProjectDO::getAreaId, reqVO.getAreaId())
                .likeIfPresent(CoreProjectDO::getContactName, reqVO.getContactName())
                .eqIfPresent(CoreProjectDO::getContactMobile, reqVO.getContactMobile())
                .likeIfPresent(CoreProjectDO::getAgentName, reqVO.getAgentName())
                .likeIfPresent(CoreProjectDO::getServiceProviderName, reqVO.getServiceProviderName())
                .eqIfPresent(CoreProjectDO::getProjectType, reqVO.getProjectType())
                .eqIfPresent(CoreProjectDO::getPlatformType, reqVO.getPlatformType())
                .eqIfPresent(CoreProjectDO::getOwnerUserId, reqVO.getOwnerUserId())
                .eqIfPresent(CoreProjectDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(CoreProjectDO::getCreateTime, reqVO.getCreateTime())
                .betweenIfPresent(CoreProjectDO::getMaintenanceStartTime, reqVO.getMaintenanceTime())
                .betweenIfPresent(CoreProjectDO::getTrafficStartTime, reqVO.getTrafficTime())
                .orderByDesc(CoreProjectDO::getId));
    }

    default List<CoreProjectDO> selectListByIds(Collection<Long> ids) {
        return selectList(new LambdaQueryWrapperX<CoreProjectDO>()
                .in(CoreProjectDO::getId, ids));
    }

    default List<CoreProjectDO> selectListByOwnerUserId(Long ownerUserId) {
        return selectList(new LambdaQueryWrapperX<CoreProjectDO>()
                .eq(CoreProjectDO::getOwnerUserId, ownerUserId));
    }

}